<template>


  <el-card shadow="hover" v-for="d in aaa">
    <el-row :gutter="20" >
      <el-col :span="9" style="margin: auto">
        <router-link to="/detail" style="text-decoration: none;">
          <h2>{{d.title}}</h2>
        </router-link>
        <span style="color: #c7c7c7"> {{d.experience}} | {{d.degree}} | {{d.salary}} </span>
      </el-col>
      <el-col :span="6" style="margin: auto">
        <el-row :gutter="5" style="text-align: center">
          <el-col :span="8">
            <h4>38</h4>
            <span style="color: #c7c7c7">看过我</span>
          </el-col>
          <el-col :span="8">
            <h4 style="text-align: center">7</h4>
            <span style="color: #c7c7c7">沟通过</span>
          </el-col>
          <el-col :span="8">
            <h4 style="text-align: center">1</h4>
            <span style="color: #c7c7c7">感兴趣</span>
          </el-col>
        </el-row>
      </el-col>
      <el-col :span="5" style="margin: auto">
        <h4>是否开放</h4>
        <el-switch
            v-model="value1"
            inline-prompt
            active-text="是"
            inactive-text="否"
        />
      </el-col>
      <el-col :span="4" style="margin: auto">
        <el-button type="primary" @click="update(d.id)">编辑
        </el-button
        >
      </el-col>
    </el-row>
  </el-card>

  <el-pagination style="margin: 10px 0 0 -20px;float: right"
                 background
                 @prev-click="prePage()"
                 @next-click="nextPage()"
                 @update:current-page="currentPage()"
                 layout="prev,pager,next" :total="page.total" />

</template>

<script setup>
import axios from "axios";
import qs from "qs";
import router from "@/router";
import {onMounted, ref} from "vue";

const value1 = ref(true)

const aaa = ref([]);

const userId = ref({id:''});

const page = ref({currentPage:'1',total:'',maxPage:''});

let user=localStorage.user?JSON.parse(localStorage.user):null;
let Authorization=localStorage.user?JSON.parse(localStorage.Authorization):null;


const prePage = ()=>{
  page.value.currentPage = page.value.currentPage-1;
  loadContents();
}

const nextPage = ()=>{
  page.value.currentPage = page.value.currentPage+1;
  loadContents();
}

// const currentPage = ()=>{
//   page.value.currentPage = ;
//   loadContents();
// }

const loadContents = () => {
  userId.value.id = user;
  axios.get('http://localhost:39281/v1/job/recruit/list/' + userId.value.id + '/page/'+page.value.currentPage,
      {
        headers:{Authorization}
      })
      .then((response) => {
        if (response.data.state == 20000) {
          console.log(response.data.data);
          page.value.currentPage = response.data.data.currentPage;
          page.value.total = response.data.data.total;
          page.value.maxPage = response.data.data.maxPage;
          aaa.value = response.data.data.list;
         console.log(aaa.value);
        }
      })
}

const update = (c) => {
  //跳转到发布页面并把内容id传递过去
  router.push('/postPosition?id=' + c);
}

onMounted(()=>{

  loadContents();
})

</script>

<style scoped>

</style>